package com.taotao.job.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Preconditions;
import com.taotao.job.dao.JobInfoMapper;
import com.taotao.job.model.entity.JobInfo;
import com.taotao.job.service.JobInfoService;
import com.taotao.job.util.EntityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Set;

/**
 * <p>
 * 任务信息服务接口实现类
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2021-03-14 21:43:18
 */
@Slf4j
@Service
public class JobInfoServiceImpl implements JobInfoService {
    @Resource
    private JobInfoMapper jobInfoMapper;


    @Override
    public void softDelByIds (Set<java.lang.Long> ids, Long userId) {
        Preconditions.checkArgument(null != ids && ids.size() > 0);
        Preconditions.checkArgument(null != userId);

        jobInfoMapper.softDelByPks(ids,userId,new Date());
    }

    @Override
    public JobInfo queryById (java.lang.Long id) {
        Preconditions.checkArgument(null != id);

        return jobInfoMapper.selectByPk(id);
    }

    @Override
    public void addOrUpdate(JobInfo jobInfo, Long userId) {
        Preconditions.checkArgument(null != jobInfo);
        Preconditions.checkArgument(null != userId);

        if (null == jobInfo.getId()) {
            EntityUtils.setPo5Field(userId, new Date(), jobInfo);
            jobInfoMapper.insert(jobInfo);
        } else {
            EntityUtils.setPo2Field(userId, new Date(), jobInfo);
            //这里不做删除
            jobInfo.setIsDel(null);
            jobInfoMapper.updateByPk(jobInfo);
        }

    }

    @Override
    public PageInfo<JobInfo> queryByPage(JobInfo param, int pageNum, int pageSize) {
        Preconditions.checkArgument(pageNum > 0);
        Preconditions.checkArgument(pageSize > 0);

        Page<JobInfo> page =  jobInfoMapper.selectByPage(param,pageNum,pageSize);

        return new PageInfo<>(page);
    }






//------------以上是生成代码-----------------------------------------------------------------------------------------------------------------









}
